package com.huike.web.controller.report;


import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }

    //今日简报
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){

        IndexTodayInfoVO indexTodayInfoVO = new IndexTodayInfoVO();

        Integer todayCluesNum = reportService.getTodayCluesNum();
        Integer todayBusinessNum = reportService.getTodayBusinessNum();
        Integer todayContractNum = reportService.getTodayContractNum();
        Double salesAmount = reportService.getSalesAmountToday();

        if (salesAmount == null) {
            salesAmount = 0.0;
        }

        indexTodayInfoVO.setTodayCluesNum(todayCluesNum);
        indexTodayInfoVO.setTodayBusinessNum(todayBusinessNum);
        indexTodayInfoVO.setTodayContractNum(todayContractNum);
        indexTodayInfoVO.setTodaySalesAmount(salesAmount);

        return AjaxResult.success(indexTodayInfoVO);

    }



    //待办事项
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){

        IndexTodoInfoVO indexTodoInfoVO = new IndexTodoInfoVO();
        Integer tofollowedCluesNum=reportService.getTofollowedCluesNum(beginCreateTime,endCreateTime);
        Integer tofollowedBusinessNum=reportService.getTofollowedBusinessNum(beginCreateTime,endCreateTime);
        Integer toallocatedCluesNum=reportService.getToallocatedCluesNum(beginCreateTime,endCreateTime);
        Integer toallocatedBusinessNum=reportService.getToallocatedBusinessNum(beginCreateTime,endCreateTime);

        indexTodoInfoVO.setTofollowedCluesNum(tofollowedCluesNum);
        indexTodoInfoVO.setTofollowedBusinessNum(tofollowedBusinessNum);
        indexTodoInfoVO.setToallocatedCluesNum(toallocatedCluesNum);
        indexTodoInfoVO.setToallocatedBusinessNum(toallocatedBusinessNum);

        return AjaxResult.success(indexTodoInfoVO);
    }

}